/*
 * @Author: your name
 * @Date: 2021-12-17 15:30:52
 * @LastEditTime: 2022-05-19 10:39:21
 * @LastEditors: 陈宇 975155172@qq.com
 * @Description: 博客文章相关控制器
 * @FilePath: 
 */
import { Controller, Post, Body } from '@nestjs/common';
import { AbstractService } from './abstract.service';
import { Abstract as AbstractApi } from './abstract';

import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { CreatePostDto, AbstractDto, AbstractBase, AbstractShowType, AddAbstractDto, AbstractDetailsDto } from './dto/create-post.dot';

@ApiTags("文章")
@Controller('abstract')
export class AbstractController {
  constructor(
		private readonly abstractSever: AbstractService,
		private readonly abstract: AbstractApi
	) {}
  
  // 获取列表
  @ApiOperation({ summary: '获取列表' })
  @Post('list')
  list(@Body() body: CreatePostDto): Promise<AbstractDto> {
    return this.abstractSever.list(body);
  }

  // 获取文章详情
  @ApiOperation({ summary: '获取文章详情' })
  @Post('details')
  details(@Body() body: AbstractDetailsDto): Promise<any> {
    return this.abstractSever.details(body);
  }

  // 点赞
  @ApiOperation({ summary: '点赞' })
  @Post('addPraise')
  addPraise(@Body() body): Promise<AbstractBase[]> {
    return this.abstractSever.addPraise(body);
  }

  // 增加查看次数
  @ApiOperation({ summary: '增加查看次数' })
  @Post('addSeeNum')
  addSeeNum(@Body() body): Promise<AbstractBase[]> {
    return this.abstractSever.addSeeNum(body);
  }

  // 文章显示状态修改
  @ApiOperation({ summary: '文章显示状态修改' })
  @Post('articleShow')
  articleShow(@Body() body: AbstractShowType): Promise<AbstractDto> {
    return this.abstractSever.articleShow(body);
  }

  // 添加 / 修改 文章
  @ApiOperation({ summary: '添加 / 修改 文章' })
  @Post('addAndUpdateArticle')
  addAndUpdateArticle(@Body() body: AddAbstractDto): Promise<AbstractDto> {
    if (body.id) {
      return this.abstractSever.updateArticleTransaction(body);
    } else {
      return this.abstractSever.addArticle(body);
    }
  }

  // 删除文章
  @ApiOperation({ summary: '删除文章' })
  @Post('removeArticle')
  removeArticle(@Body() body: AddAbstractDto): Promise<AbstractDto> {
    return this.abstractSever.removeArticle(body);
  }
}
